package com.stephentuso.welcome;

import ohos.agp.components.Component;

/**
 * Created by stephentuso on 11/16/15.
 */
/* package */ class WelcomeViewHider implements OnWelcomeScreenPageChangeListener {

    private Component view;
    private Integer lastPage = null;
    private boolean isRtl = false;
    private OnViewHiddenListener listener = null;
    private boolean enabled = false;

    public WelcomeViewHider(Component viewToHide) {
        view = viewToHide;
    }

    public interface OnViewHiddenListener {
        void onViewHidden();
    }

    public void setOnViewHiddenListener(OnViewHiddenListener listener) {
        this.listener = listener;
    }

    @Override
    public void setup(WelcomeConfiguration config) {
        enabled = config.getSwipeToDismiss();
        lastPage = config.lastPageIndex();
        isRtl = config.isRtl();
    }

    @Override
    public void onPageSliding(int position, float positionOffset, int positionOffsetPixels) {
        //Not needed
    }

    @Override
    public void onPageChosen(int position) {
        if (!enabled) {
            return;
        }

        if (position == lastPage && listener != null) {
            listener.onViewHidden();
        }
    }

    @Override
    public void onPageSlideStateChanged(int state) {
        //Not needed
    }
}
